﻿using Newtonsoft.Json.Linq;
using Server.Common;
using Server.Utils;
using Spire.Pdf;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Threading.Tasks;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Server
{
    public class FileConversion
    {
        const string _setFileStatus = "/FileInfo/setFileStatus";
        const string _getFilesByTaskCode = "/FileInfo/getFilesByTask";
        //系统临时目录
        static string _temp = Environment.GetEnvironmentVariable("TEMP");
        public FileConversion()
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            string licenseBase64 = "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxMaWNlbnNlIHhtbG5zOnhzZD0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEiIHhtbG5zOnhzaT0iaHR0cDovL3d3dy53My5vcmcvMjAwMS9YTUxTY2hlbWEtaW5zdGFuY2UiIEtleT0iT0Z0QzlGNEJBRHhOUml0OCtsY3BZTDh3Z2pLNXQrRmlBOEkxODZTWWZLeCt3RmNOQnJzN1Z4UVhYSjZZM3NTa2pZdnl3bzFYbWthT21VRmhCY3BYSjU5MTBmdC9OemEyODhKYzIreEd3OWFkRkVaaXdpWnRPemZoSXlCWjR0dlRVc0NBcW1yenRvbkVLVHZhaGZtTWtHa1g2VndQazhGcnkwc01BU2dnZWtvSXdUVmg4ZTFsV3VzN3lWYlBVLy9VOC9KbU1iMkRHUWtoTHNpWnF0MHRuYWY1Ri85V29NSW5RdEY4ejF6VEp3U3F2WEY2V3d5a1BzMFc5cDdMKzh6SGQvbWZzRVdlb3NrOElJU3Y4YkF0OFhEZFJNOHlteXg5MW5xVVpsUkVlT1h5UG5JL1NKVkE5Q1RHa3VJZERUTVZvT2FZSXhCdCtLMXpNcjQrR1FKM3hxTmc2NGVxZTZGcDFCd3V3N21jT3dnSlBvbCtIS0lpU3RGaldCcUdJSHRHVmVndGV4c1pMZjF6WGh6MEQ5ZTB2d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QkJPE51bWJlck9mUGVybWl0dGVkU2l0ZT4yMTQ3NDgzNjQ3PC9OdW1iZXJPZlBlcm1pdHRlZFNpdGU+DQoJCQk8L1N1YnNjcmlwdGlvbj4NCgkJPC9Qcm9kdWN0Pg0KCTwvUHJvZHVjdHM+DQoJPElzc3Vlcj4NCgkJPE5hbWU+ZS1pY2VibHVlPC9OYW1lPg0KCQk8RW1haWw+c2FsZXNAZS1pY2VibHVlLmNvbTwvRW1haWw+DQoJCTxVcmw+aHR0cDovL3d3dy5lLWljZWJsdWUuY29tPC9Vcmw+DQoJPC9Jc3N1ZXI+DQo8L0xpY2Vuc2U+";
            Stream stream = new MemoryStream(Convert.FromBase64String(licenseBase64));
            Spire.License.LicenseProvider.SetLicenseFileStream(stream);
        }

        #region 分割指定页码PDF文件
        /// <summary>
        /// 分割指定页码PDF文件
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public async Task<object> SplitPdfFile(dynamic arg)
        {
            //{
            //    "TaskCode":"",
            //    "SourcePath":"",
            //    "TargetPath":"",
            //    "CheckPages":[]
            //}

            //arg = new
            //{
            //    TaskCode="",
            //    SourcePath = @"E:\文档\Angular Js\AngularJS开发指南.pdf",
            //    TargetPath = @"E:\桌面\软件文档",
            //    FileFormat = "pNg",
            //    FileName = "",
            //    CheckPages = new int[] { 20, 1, 5, 7 }
            //};
            return await Task.Run(() =>
            {
                Log4Util.LogInstance.Info(typeof(FileConversion), "开始分割PDF文件");

                string fileCode = (string)arg.FileCode;
                string fileFormat = (string)arg.FileFormat;
                string sourcePath = (string)arg.SourcePath;
                string targetPath = (string)arg.TargetPath;
                object[] checkPages = (object[])arg.CheckPages;
                string sourceFileName = Path.GetFileNameWithoutExtension(sourcePath);
                Log4Util.LogInstance.Info(typeof(FileConversion), $"开始处理文件：{sourcePath}");

                int fileStatus = 2;
                try
                {
                    var pdfFiles = PdfFormatUtil.SplitFile(sourcePath, checkPages);

                    foreach (var item in pdfFiles)
                    {
                        FileUtil.WriteFile($"{targetPath}\\{sourceFileName}_{item.Key}.pdf", item.Value);
                    }
                }
                catch (Exception ex)
                {
                    fileStatus = 3;
                    Log4Util.LogInstance.Error(typeof(FileConversion), "分割PDF异常", ex);
                    throw ex;
                }
                finally
                {
                    Log4Util.LogInstance.Info(typeof(FileConversion), "分割PDF文件完成");
                    HttpUtil.HttpPost(_setFileStatus, new JObject() { { "fileCode", fileCode }, { "fileStatus", fileStatus } });

                }
                return true;
            });
        }
        #endregion

        #region 合并指定页码PDF文件
        /// <summary>
        /// 合并指定页码PDF文件
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public async Task<object> MergePdfFile(dynamic arg)
        {
            //{
            //    "TaskCode":"",
            //    "SourcePath":"",
            //    "TargetPath":"",
            //    "FileName":"",
            //    "CheckPages":[]
            //}

            //arg = new
            //{
            //    TaskCode = "2000000000000",
            //    Total = 2,
            //    //SourcePath = @"E:\文档\Angular Js\AngularJS开发指南.pdf",
            //    SourcePath = @"E:\文档\Angular Js\使用AngularJS开发下一代WEB应用5295b5bf8d44f.pdf",
            //    TargetPath = @"E:\桌面\软件文档",
            //    FileFormat = "pNg",
            //    FileName = @"E:\桌面\软件文档\使用AngularJS开发下一代WEB应用.pdf",
            //    CheckPages = new object[] { 20, 1, 5, 7 }
            //};
            return await Task.Run(() =>
            {
                Log4Util.LogInstance.Info(typeof(FileConversion), "开始合并PDF文件");

                arg = Common.Common.DecodeParameter(arg);

                string taskCode = (string)arg.TaskCode;
                string fileCode = (string)arg.FileCode;
                string fileFormat = (string)arg.FileFormat;
                int total = (int)arg.Total;
                string sourcePath = (string)arg.SourcePath;
                string targetPath = (string)arg.TargetPath;
                string fileName = (string)arg.FileName;
                bool isMerge = (bool)arg.IsMerge;
                object[] checkPages = (object[])arg.CheckPages;

                //string taskCode = (string)arg.TaskCode;
                //string fileCode = (string)arg.FileCode;
                //string fileFormat = (string)arg.FileFormat;
                //int total = (int)arg.Total;
                //string sourcePath = (string)arg.SourcePath;
                //string targetPath = (string)arg.TargetPath;
                //string fileName = (string)arg.FileName;
                //bool isMerge = (bool)arg.IsMerge;
                //object[] checkPages = (object[])arg.CheckPages;

                Log4Util.LogInstance.Info(typeof(FileConversion), $"开始处理文件：{sourcePath}");

                int fileStatus = 2;
                try
                {
                    var pdfBytes = PdfFormatUtil.MergeFile(sourcePath, checkPages);

                    string dir = $"{_temp}\\{taskCode}";

                    if (!isMerge)
                    {
                        FileUtil.WriteFile($"{targetPath}\\{Path.GetFileNameWithoutExtension(sourcePath)}.pdf", pdfBytes);
                        return true;
                    }

                    //FileUtil.WriteFile($"{dir}\\{Path.GetFileNameWithoutExtension(sourcePath)}.pdf", pdfBytes);
                    FileUtil.WriteFile($"{dir}\\{fileCode}.pdf", pdfBytes);


                    //已转换文件
                    var processedFiles = Directory.GetFiles(dir);
                    if (processedFiles.Length >= total)
                    {
                        processedFiles = GetFilesByTaskcode(taskCode, processedFiles.ToList());
                        //将文件复制到输出目录
                        //var pdfFiles = processedFiles.ToList();
                        if (!string.IsNullOrWhiteSpace(fileName))
                        {
                            try
                            {
                                string pdfFilePath = FileUtil.GetFileName($"{targetPath}\\{Path.GetFileNameWithoutExtension(fileName)}.pdf");

                                //合并已处理PDF
                                PdfFormatUtil.MergePdfFiles(processedFiles).SaveToFile(pdfFilePath);

                                foreach (var item in processedFiles)
                                {
                                    File.Delete(item);
                                }
                                //删除目录
                                Directory.Delete(dir);
                            }
                            catch (Exception ex)
                            {
                                Log4Util.LogInstance.Error(typeof(FileConversion), "合并PDF异常", ex);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    fileStatus = 3;
                    Log4Util.LogInstance.Error(typeof(FileConversion), "合并PDF异常", ex);
                    throw ex;
                }
                finally
                {
                    Log4Util.LogInstance.Info(typeof(FileConversion), "合并PDF文件完成");
                    HttpUtil.HttpPost(_setFileStatus, new JObject() { { "fileCode", fileCode }, { "fileStatus", fileStatus } });
                }


                return true;
            });
        }
        #endregion

        #region 转换指定页码PDF为Image
        /// <summary>
        /// 转换指定页码PDF为Image
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public async Task<object> ToImagesByPDF(dynamic arg)
        {
            //{
            //    "TaskCode":"",
            //    "SourcePath":"",
            //    "TargetPath":"",
            //    "FileFormat":"",
            //    "CheckPages":[]
            //}

            //arg = new
            //{
            //    TaskCode = "",
            //    SourcePath = @"E:\文档\Angular Js\AngularJS开发指南.pdf",
            //    TargetPath = @"E:\桌面\软件文档",
            //    FileFormat = "pNg",
            //    FileName = "",
            //    CheckPages = new int[] { 20, 1, 5, 7 }
            //};
            return await Task.Run(() =>
            {
                Log4Util.LogInstance.Info(typeof(FileConversion), "开始PDF转换Image文件");
                string fileCode = (string)arg.FileCode;
                string sourcePath = (string)arg.SourcePath;
                string targetPath = (string)arg.TargetPath;
                string fileFormat = ((string)arg.FileFormat).ToLower();
                object[] checkPages = (object[])arg.CheckPages;

                Log4Util.LogInstance.Info(typeof(FileConversion), $"开始处理文件：{sourcePath}");

                int fileStatus = 2;
                try
                {
                    var pdfImages = PdfFormatUtil.ToImages(sourcePath, checkPages);
                    ImageFormat format = null;

                    if (fileFormat == "png")
                    {
                        format = ImageFormat.Png;
                    }
                    else if (fileFormat == "bmp")
                    {
                        format = ImageFormat.Bmp;
                    }
                    else
                    {
                        format = ImageFormat.Jpeg;
                    }

                    string imgPath = null;
                    foreach (var item in pdfImages)
                    {
                        imgPath = FileUtil.GetFileName($"{targetPath}\\{Path.GetFileNameWithoutExtension(sourcePath)}_{item.Key}.{fileFormat}");
                        item.Value.Save(imgPath, format);
                    }
                }
                catch (Exception ex)
                {
                    fileStatus = 3;
                    Log4Util.LogInstance.Error(typeof(FileConversion), "转换指定PDF异常", ex);
                    throw ex;
                }
                finally
                {
                    Log4Util.LogInstance.Info(typeof(FileConversion), "PDF转换Image文件完成");
                    HttpUtil.HttpPost(_setFileStatus, new JObject() { { "fileCode", fileCode }, { "fileStatus", fileStatus } });
                }


                return true;
            });
        }
        #endregion

        #region 转换指定页码PDF为Word
        /// <summary>
        /// 转换指定页码PDF为Word
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public async Task<object> ToWordByPDF(dynamic arg)
        {
            //{
            //    "TaskCode":"",
            //    "SourcePath":"",
            //    "TargetPath":"",
            //    "FileName":"",
            //    "FileFormat":"",
            //    "CheckPages":[]
            //}

            //arg = new
            //{
            //    TaskCode = "P1000000000000",
            //    Total = 2,
            //    SourcePath = @"E:\文档\Angular Js\使用AngularJS开发下一代WEB应用5295b5bf8d44f.pdf",
            //    TargetPath = @"E:\桌面\软件文档",
            //    FileFormat = "doC",
            //    FileName = @"E:\文档\Angular Js\AngularJS开发指南1111.pdf",
            //    CheckPages = new object[] { 20, 1, 5, 7 }
            //};
            return await Task.Run(() =>
            {
                Log4Util.LogInstance.Info(typeof(FileConversion), "PDF开始转换Word文件");
                string taskCode = (string)arg.TaskCode;
                string fileCode = (string)arg.FileCode;
                int total = (int)arg.Total;
                string sourcePath = (string)arg.SourcePath;
                string targetPath = (string)arg.TargetPath;
                string fileName = (string)arg.FileName;
                bool isMerge = (bool)arg.IsMerge;
                string fileFormat = ((string)arg.FileFormat).ToLower().Trim();
                object[] checkPages = (object[])arg.CheckPages;

                Log4Util.LogInstance.Info(typeof(FileConversion), $"开始处理文件：{sourcePath}");

                int fileStatus = 2;
                try
                {
                    var wordBytes = PdfFormatUtil.ToWord(sourcePath, checkPages, fileFormat == "doc" ? FileFormat.DOC : FileFormat.DOCX);
                    Log4Util.LogInstance.Info(typeof(FileConversion), $"PDF转Word完成，文件大小：{wordBytes.Length}");
                    if (!isMerge)
                    {
                        FileUtil.WriteFile($"{targetPath}\\{Path.GetFileNameWithoutExtension(sourcePath)}.{fileFormat}", wordBytes);
                        return true;
                    }

                    string dir = $"{_temp}\\{taskCode}";

                    FileUtil.WriteFile($"{dir}\\{fileCode}.{fileFormat}", wordBytes);

                    //已转换文件
                    var processedFiles = Directory.GetFiles(dir);
                    if (processedFiles.Length >= total)
                    {
                        //将文件复制到输出目录
                        var wordFiles = GetFilesByTaskcode(taskCode, processedFiles.ToList());
                        if (!string.IsNullOrWhiteSpace(fileName))
                        {
                            try
                            {
                                string wordFilePath = $"{targetPath}\\{Path.GetFileNameWithoutExtension(fileName)}.{fileFormat}";
                                //合并已处理PDF
                                wordBytes = PdfFormatUtil.MergeWordFiles(wordFiles, fileFormat == "doc" ? Spire.Doc.FileFormat.Doc : Spire.Doc.FileFormat.Docx);
                                FileUtil.WriteFile(wordFilePath, wordBytes);
                                foreach (var item in wordFiles)
                                {
                                    File.Delete(item);
                                }
                                //删除目录
                                Directory.Delete(dir);
                            }
                            catch (Exception ex)
                            {
                                Log4Util.LogInstance.Error(typeof(FileConversion), "PDF合并Word异常", ex);
                            }
                        }
                    }
                    return true;
                }
                catch (Exception ex)
                {
                    fileStatus = 3;
                    Log4Util.LogInstance.Error(typeof(FileConversion), "转换指定PDF成Word异常", ex);
                    throw ex;
                }
                finally
                {
                    Log4Util.LogInstance.Info(typeof(FileConversion), "PDF转换Word文件完成");
                    HttpUtil.HttpPost(_setFileStatus, new JObject() { { "fileCode", fileCode }, { "fileStatus", fileStatus } });
                    Log4Util.LogInstance.Info(typeof(FileConversion), "PDF转换Word文件状态修改完成");
                }
            });
        }
        #endregion

        #region 转换图片为PDF
        /// <summary>
        /// 转换指定页码PDF为Word
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public async Task<object> ToPdfByImage(dynamic arg)
        {
            //{
            //    "TaskCode":"",
            //    "SourcePath":"",
            //    "TargetPath":"",
            //    "FileName":"",
            //    "FileFormat":"",checkPage
            //    "CheckPages":[]
            //}

            //arg = new
            //{
            //    TaskCode = "P1000000000000",
            //    Total = 2,
            //    SourcePath = @"D:\Git\OCR-Platform\03_产品设计\设计图\客户端界面+标注切图\客户端设计稿\客户端界面\PDF拆分.png",
            //    TargetPath = @"E:\桌面\软件文档",
            //    FileName = @"E:\桌面\软件文档\图片合并.pdf"
            //};
            return await Task.Run(() =>
            {
                Log4Util.LogInstance.Info(typeof(FileConversion), "Image开始转换PDF文件");
                string taskCode = (string)arg.TaskCode;
                string fileCode = (string)arg.FileCode;
                string fileFormat = (string)arg.FileFormat;
                int total = (int)arg.Total;
                string sourcePath = (string)arg.SourcePath;
                string targetPath = (string)arg.TargetPath;
                string fileName = (string)arg.FileName;
                bool isMerge = (bool)arg.IsMerge;

                Log4Util.LogInstance.Info(typeof(FileConversion), $"开始处理文件：{sourcePath}");

                int fileStatus = 2;
                try
                {
                    var pdfBytes = PdfFormatUtil.ToPDF(sourcePath);

                    if (!isMerge)
                    {
                        FileUtil.WriteFile($"{targetPath}\\{Path.GetFileNameWithoutExtension(sourcePath)}.pdf", pdfBytes);
                        return true;
                    }

                    string dir = $"{_temp}\\{taskCode}";

                    FileUtil.WriteFile($"{dir}\\{fileCode}.pdf", pdfBytes);

                    //已转换文件
                    var processedFiles = Directory.GetFiles(dir);
                    if (processedFiles.Length >= total)
                    {
                        //将文件复制到输出目录
                        var wordFiles = processedFiles.ToList();
                        if (!string.IsNullOrWhiteSpace(fileName))
                        {
                            string pdfFilePath = FileUtil.GetFileName($"{targetPath}\\{Path.GetFileNameWithoutExtension(fileName)}.pdf");
                            //合并已处理PDF
                            //if (File.Exists(pdfFilePath)) return true;
                            try
                            {
                                using (PdfDocument pdfFile = PdfFormatUtil.MergePdfFiles(processedFiles))
                                {
                                    try
                                    {
                                        pdfFile.SaveToFile(pdfFilePath);
                                    }
                                    catch
                                    {

                                    }
                                }
                                foreach (var item in wordFiles)
                                {
                                    File.Delete(item);
                                }
                                //删除目录
                                Directory.Delete(dir);
                            }
                            catch (Exception ex)
                            {
                                Log4Util.LogInstance.Error(typeof(FileConversion), "Image合并Word异常", ex);
                            }
                        }
                    }

                    return true;
                }
                catch (Exception ex)
                {
                    fileStatus = 3;
                    Log4Util.LogInstance.Error(typeof(FileConversion), "图片转PDF异常", ex);
                    throw ex;
                }
                finally
                {
                    Log4Util.LogInstance.Info(typeof(FileConversion), "Image转换PDF文件完成");
                    HttpUtil.HttpPost(_setFileStatus, new JObject() { { "fileCode", fileCode }, { "fileStatus", fileStatus } });
                }
            });
        }
        #endregion

        private string[] GetFilesByTaskcode(string taskCode, List<string> filePaths)
        {
            try
            {
                List<string> paths = new List<string>();
                JArray files = HttpUtil.HttpGet<JArray>(_getFilesByTaskCode + $"?taskCode={taskCode}");

                foreach (JObject item in files)
                {
                    int index = filePaths.FindIndex(x => x.IndexOf(item.GetValue("taskCode").ToString()) > 0 && x.IndexOf(item.GetValue("fileCode").ToString()) > 0);
                    if (index < 0) continue;
                    paths.Add(filePaths[index]);
                    filePaths.RemoveAt(index);
                }
                paths.AddRange(filePaths);
                return paths.ToArray();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
